<template>
	<view class="serve">
		<view class="nav">
			<u-tabs :list="list1" lineColor="#FF5B1A" :activeStyle="{color: '#FF5B1A'}" @click="change" :scrollable="false"></u-tabs>
		</view>
		<scroll-view scroll-y="true" class="main" @scrolltolower="lower()">
			<view class="list" v-for="(item,index) of list">
				<image :src="oss(item.images[0])" class="cover" mode="aspectFill"></image>
				<view class="info">
					<view class="t">{{item.name}}</view>
					<view class="b">{{item.cate.name}}</view>
				</view>
				<view class="numBox">
					<view class="t"><text class="icon">¥</text>{{item.price}}/{{item.unit_price}}</view>
					<view class="b">
						<view class="edit" v-if="type !== 1" @click="authTo(`pages/my/skill/skilledit?id=${item.id}`)">编辑</view>
						<view class="down" v-if="type === 1"  @click="toastInfo(item.id,2,'')">下架</view>
						<view class="down" v-if="type === 2" @click="toastInfo(item.id,3,'')">上架</view>
						<view class="del" v-if="type !== 1" @click="toastInfo(item.id,1,'')">删除</view>
						<view class="del" v-if="type == -1" @click="toastInfo(item.id,4,item.note)">拒绝原因</view>
					</view>
				</view>
			</view>
			<u-empty v-if="list.length === 0 && finish" mode="data" marginTop="100">
			</u-empty>
		</scroll-view>
		<u-modal :show="show" :closeOnClickOverlay="true" title="确定要删除该技能" :showCancelButton="true" @cancel="show = false" @confirm="confirm"></u-modal>
		<u-modal :show="show1" :closeOnClickOverlay="true" title="确定要下架该技能" :showCancelButton="true" @cancel="show1 = false" @confirm="confirm1"></u-modal>
		<u-modal :show="show2" :closeOnClickOverlay="true" title="确定要上架该技能" :showCancelButton="true" @cancel="show2 = false" @confirm="confirm2"></u-modal>
		<u-modal :show="show3" :closeOnClickOverlay="true" :title="note"  @cancel="show3 = false" @confirm="show3 = false"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '上架',
					type: 1
				}, {
					name: '下架',
					type: 2
				},  {
					name: '待审核',
					type: 0
				}, {
					name: '审核失败',
					type: -1
				}],
				page: 1,
				finish: false,
				type: 1,
				list: [],
				id: '',
				show: false,
				show1: false,
				show2: false,
				show3: false,
				note: ''
			};
		},
		onLoad() {
			this.getList()
		},
		methods: {
			toastInfo(id,type,note) {
				this.id = id
				if(type == 1){
					this.show = true
				} else if(type == 2){
					this.show1 = true
				} else if(type == 3){
					this.show2 = true
				} else if(type == 4){
					this.note = note
					this.show3 = true
				}
				// switch (type){
				// 	case 1:
				// 	this.show = true
				// 	break;
				// 	case 2:
				// 	this.show1 = true
				// 	break;
				// 	case 3:
				// 	this.show2 = true
				// 	break;
				// 	case 4:
				// 	this.show3 = true
				// 	this.note = note
				// 	break;
				// }
			},
			confirm2() {
				this.show2 = false
				uni.$u.http.post('/userskill ', {
					types: 'up',
					id: this.id,
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
				
				})
			},
			confirm1() {
				this.show1 = false
				uni.$u.http.post('/userskill ', {
					types: 'off',
					id: this.id,
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
				
				})
			},
			confirm() {
				this.show = false
				uni.$u.http.post('/userskill ', {
					types: 'del',
					id: this.id,
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
				
				})
			},
			change(e) {
				console.log(e)
				this.type = e.type
				this.reload()
			},
			reload() {
				this.page = 1
				this.finish = false
				this.list = []
				this.getList()
			},
			lower() {
				this.page++
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/userskill', {
					page: this.page,
					type: this.type
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {
		
				})
			}
		}
	}
</script>

<style lang="scss">
	// page{
	// 	height: 100%;
	// 	background: #f6f6f6;
	// }
	.serve{
		height: 100vh;
		position: relative;
		background: #f6f6f6;
	}
	.nav{
		display: flex;
		align-items: center;
		justify-content: center;
		height: 90rpx;
	}
.main{
	position: absolute;
	left: 0;
	width: 100%;
	bottom: 0;
	top: 90rpx;
	.list{
		margin: 0 20rpx 20rpx;
		background-color: #fff;
		box-shadow: 0 0 10rpx rgba(98, 98, 98, 0.2);
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		padding: 20rpx;
		.cover{
			width: 120rpx;
			height: 120rpx;
			border-radius: 10rpx;
		}
		.info{
			flex: 1;
			margin: 0 20rpx;
			.t{
				font-weight: bold;
				font-size: 32rpx;
				color: #191615;
			}
			.b{
				color: #999999;
				font-size: 30rpx;
				margin-top: 20rpx;
			}
		}
		.numBox{
			.t{
				font-size: 40rpx;
				color: #FF5B1A;
				font-weight: bold;
				text-align: right;
				.icon{
					font-size: 30rpx;
				}
			}
			.b{
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #666;
				margin-top: 20rpx;
				justify-content: flex-end;
				.edit{
					margin-left: 20rpx;
				}
				.down{
					margin-left: 20rpx;
				}
				.del{
					margin-left: 20rpx;
				}
			}
		}
	}
}
</style>
